package com.lksy.web.controller.system;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lksy.web.controller.BaseController;
import com.lksy.web.service.system.AdminService;

/**
 * 
 * @author jzx
 * @date 2016-08-03 10:40:51 星期三
 *	
 * 用了差不多三天时间终于又到了说再见的时候了
 * 一定要記的你的出发点，那样才不会半途而废
 */
@Controller
@RequestMapping("syslog")
public class SystemLogController extends BaseController {

	@Inject
	private AdminService adminService;;
	
	@RequestMapping(value = "list")
	public String list(Model model) {
		List<Map<String,Object>> data = adminService.loadAllSysLog();
		
		// 1.8
//		data.forEach(x -> {
//			Map<String,Object> map = x;
//			String create_time = parseDate(map.get("create_time") + "");
//			map.put("create_time", create_time);
//		});
		
		Collections.sort(data,new Comparator<Map<String,Object>>() {

			@Override
			public int compare(Map<String, Object> o1, Map<String, Object> o2) {
				return (o2.get("create_time") + "").compareTo(o1.get("create_time") + "");
			}
		});
		
		model.addAttribute("data", data);
		return "/system/systeminfo";
	}
	
	@RequestMapping(value = "toLoglist")
	public String tolist(Model model) {
		model.addAttribute("mainPage", "/syslog/list");
		return "/system/main";
	}
}
